package com.fengling.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Slf4j
@Component

public class TimeAspect {
   /* @Around("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")*/

    @Around("@annotation(com.fengling.aop.MyAop)")
    public Object recordTime(ProceedingJoinPoint joinPoint)throws Throwable{
        log.info("TimeAspect around before ...");


        String className=joinPoint.getTarget().getClass().getName();    //获取目标对象的类名
        log.info("目标对象的类名:{}",className);
        String methodName=joinPoint.getSignature().getName();           //获取目标方法的方法名
        log.info("目标对象的方法名：{}",methodName);
        Object[] args=joinPoint.getArgs();                              //获取目标方法运行时传入的参数
        log.info("目标方法运行时传入的参数：{}", Arrays.toString(args));




        long begin=System.currentTimeMillis();


       Object result= joinPoint.proceed();                              //放行 目标方法执行


       long end=System.currentTimeMillis();
        log.info("TimeAspect around after ...");
        log.info("方法返回值：{}",result);
       log.info(joinPoint.getSignature()+"方法执行耗时：{}ms",end-begin);

       return result;

    }
}


